import 'dart:convert';

import 'package:flutter/cupertino.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/12/11.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单 mineQuestion
class MineQuestionBean {
  int id;
  int mineId;
  String questionTitle;
  String questionUid;

  //是否是默认题库
  bool isDefault;

  int questionDef;
  int questionDelete;
  String questContent;
  String updateDate;
  String createTime;
  int parent;
  List<QuestionTypeListBean> questionTypeList;

  MineQuestionBean.fromJson(Map<String, dynamic> map) {
    this.id = map["id"];
    this.mineId = map["mineId"];
    this.questionTitle = map["questionTitle"];
    this.questionUid = map["questionUid"];

    this.isDefault = map["defaultQ"];

    this.questionDef = map["questionDef"];
    this.questionDelete = map["questionDelete"];
    this.questContent = map["questContent"];
    this.createTime = map["createTime"];

    List list = map["questionTypeList"];
    if (list != null) {
      questionTypeList = [];
      list.forEach((element) {
        questionTypeList.add(QuestionTypeListBean.fromJson(element));
      });
    }
  }
}

class QuestionTypeListBean {
  int typeCount;
  String questionType;

  QuestionTypeListBean.fromJson(Map<String, dynamic> map) {
    this.typeCount = map["typeCount"];
    this.questionType = map["questionType"];
  }
}

class StudyV4ModelItemBean {}

class StudyModelItemBean {
  int nodeLocation;
  String nodeType;
  String title;
  String nodeName;
  String nodeLogo;
  String nodeValue;
  List<String> nodeValues;

  Widget page;
  int pageType;

  StudyModelItemBean(this.nodeName, this.page, this.pageType);

  StudyModelItemBean.fromJson(Map<String, dynamic> map) {
    this.nodeLocation = map['nodeLocation'];
    this.nodeType = map['nodeType'];
    this.nodeName = map['nodeName'];
    this.nodeLogo = map['nodeLogo'];
    this.pageType = 0;

    var nodeValue = map['nodeValue'];
    if (nodeValue is String) {
      this.nodeValue = nodeValue;
    } else if (nodeValue is List) {
      this.nodeValues = [];
      nodeValue.forEach((element) {
        nodeValues.add(element.toString());
      });
    }

    this.title = map['title'];
  }
}

class StudyModelBean {
  /*
  "modelId": 13,
		"modelCode": "默认模板",
		"modeImg": "http://jbsc-1.oss-cn-beijing.aliyuncs.com/2df1bb2b-c6ed-4ceb-8b07-bf4dd4edd587.png",
		"modelItems": "[{\"nodeLocation\":0,\"nodeType\":\"BANNER\"},{\"nodeLocation\":1,\"title\":\"\",\"content\":\"\",\"nodeName\":\"每日一题\",\"nodeLogo\":\"http://jbsc-1.oss-cn-beijing.aliyuncs.com/2d607d11-f2aa-4e70-804f-66f6a34a9472.png\",\"nodeType\":\"CATEGORY\",\"nodeValue\":\"EVERYDAY\"},{\"nodeLocation\":2,\"title\":\"\",\"content\":\"\",\"nodeName\":\"党的建设\",\"nodeLogo\":\"http://jbsc-1.oss-cn-beijing.aliyuncs.com/2caecd61-62a1-4f26-8bc0-ca2130b1bae4.png\",\"nodeType\":\"CATEGORY\",\"nodeValue\":\"PARTY_BUILDING\",\"spacialFlag\":\"build\"},{\"nodeLocation\":3,\"title\":\"\",\"content\":\"\",\"nodeName\":\"煤矿安全\",\"nodeLogo\":\"http://jbsc-1.oss-cn-beijing.aliyuncs.com/a24f8457-a309-48ab-8d62-2602cd81076d.png\",\"nodeType\":\"CATEGORY\",\"nodeValue\":\"COAL_MINE_SAFETY\"},{\"nodeLocation\":4,\"title\":\"\",\"content\":\"\",\"nodeName\":\"矿山救援\",\"nodeLogo\":\"http://jbsc-1.oss-cn-beijing.aliyuncs.com/fea35f38-69b2-494a-8628-938f4c0ecf9d.png\",\"nodeType\":\"CATEGORY\",\"nodeValue\":\"MINE_RESCUE\"},{\"nodeLocation\":5,\"title\":\"\",\"content\":\"\",\"nodeName\":\"四类人员\",\"nodeLogo\":\"http://jbsc-1.oss-cn-beijing.aliyuncs.com/bed66333-5090-4b43-8f6d-fba60cc3f9db.png\",\"nodeType\":\"CATEGORY\",\"nodeValue\":\"THIS_MINE_QUESTION\"},{\"nodeLocation\":6,\"title\":\"\",\"content\":\"\",\"nodeName\":\"我的错题\",\"nodeLogo\":\"http://jbsc-1.oss-cn-beijing.aliyuncs.com/c6cd1d04-fc48-4ecb-8b2f-305021e767c6.png\",\"nodeType\":\"APPJUMP\",\"nodeValue\":\"ME:WRONG\"},{\"nodeLocation\":7,\"title\":\"快速练习\",\"content\":\"综合题库\",\"nodeName\":\"快速练习\",\"nodeLogo\":\"http://jbsc-1.oss-cn-beijing.aliyuncs.com/e07bfaf8-234a-43df-8559-21bba9d4e9d3.png\",\"nodeType\":\"CATEGORY\",\"nodeValue\":\"QUICK_PRACTICE\"},{\"nodeLocation\":8,\"title\":\"日常练习\",\"content\":\"\",\"nodeName\":\"日常练习\",\"nodeLogo\":\"http://jbsc-1.oss-cn-beijing.aliyuncs.com/e6423b45-cbf1-496c-89c1-5f35b4d51f4b.png\",\"nodeType\":\"CATEGORY\",\"nodeValue\":null}]",
		"mineId": 24,
		"modelStatus": 1
   */
  int modelId;
  String modelCode;
  String modeImg;
  List<StudyModelItemBean> studyModelItemList;

  StudyModelBean.fromJson(Map<String, dynamic> map) {
    this.modelId = map["modelId"];
    this.modelCode = map["modelCode"];
    this.modeImg = map["modeImg"];

    String modelItems = map["modelItems"];

    var list = jsonDecode(modelItems);
    studyModelItemList = [];
    list.forEach((element) {
      if (element != null) {
        studyModelItemList.add(StudyModelItemBean.fromJson(element));
      }
    });

    if (studyModelItemList.length > 0) {
      StudyModelItemBean first = studyModelItemList[0];
      if (first.nodeType == 'BANNER') {
        studyModelItemList.removeAt(0);
      }
    }
  }

  @override
  String toString() {
    return 'StudyModelBean{modelId: $modelId, modelCode: $modelCode, modeImg: $modeImg, studyModelItemList: $studyModelItemList}';
  }
}
